package com.ruoyi.system.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.CollectionAmount;
import com.ruoyi.system.service.CollectionAmountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 馆藏量统计 Controller
 * 提供接口给前端调用，实现前后端交互
 *
 * @author [你的名字或团队名]
 */
@RestController
@RequestMapping("/system/collectionAmount")
public class CollectionAmountController {

    @Autowired
    private CollectionAmountService collectionAmountService;

    /**
     * 查询馆藏量统计列表
     * 支持前端传参筛选，如按名称、年份查询
     */
    @GetMapping("/list")
    public AjaxResult list(CollectionAmount collectionAmount) {
        List<CollectionAmount> list = collectionAmountService.selectCollectionAmountList(collectionAmount);
        return AjaxResult.success(list);
    }

    /**
     * 根据主键ID查询馆藏量统计详情
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        CollectionAmount collectionAmount = collectionAmountService.selectCollectionAmountById(id);
        return AjaxResult.success(collectionAmount);
    }

    /**
     * 新增馆藏量统计记录
     */
    @PostMapping
    public AjaxResult add(@RequestBody CollectionAmount collectionAmount) {
        int result = collectionAmountService.insertCollectionAmount(collectionAmount);
        return AjaxResult.success(result);
    }

    /**
     * 修改馆藏量统计记录
     */
    @PutMapping
    public AjaxResult edit(@RequestBody CollectionAmount collectionAmount) {
        int result = collectionAmountService.updateCollectionAmount(collectionAmount);
        return AjaxResult.success(result);
    }

    /**
     * 删除馆藏量统计记录（单条）
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        int result = collectionAmountService.deleteCollectionAmountById(id);
        return AjaxResult.success(result);
    }

    /**
     * 批量删除馆藏量统计记录
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        int result = collectionAmountService.deleteCollectionAmountByIds(ids);
        return AjaxResult.success(result);
    }

    /**
     * 批量保存馆藏量统计数据（先删后插）
     * 前端需传包含统一年份的数据集
     */
    @PostMapping("/batchSave")
    public AjaxResult batchSave(@RequestBody List<CollectionAmount> list) {
        int result = collectionAmountService.batchSaveCollectionAmount(list);
        return AjaxResult.success(result);
    }
}